import { ApiBaseError } from "./error"

export class Result<T = any> {
  code: number

  data: T

  msg: string

  constructor(code = 500, data = null, msg = '') {
    this.code = code
    this.data = data
    this.msg = msg
  }
}

export function ajaxResultSuccess<T extends any>(data: T, msg = ''): Result<T> {
  return new Result(200, data, msg)
}

export function ajaxResultFail(msg = '', code = 500): Result<any> {
  return new Result(code, null, msg)
}

export function ajaxLogFail(msg: any) {
  throw new ApiBaseError(msg.toString())
}